<!--
 * @Author: NaturalHulk 2066634567@qq.com
 * @Date: 2024-11-04 14:58:52
 * @LastEditors: NaturalHulk 2066634567@qq.com
 * @LastEditTime: 2024-11-04 16:27:50
 * @FilePath: /xhs-mom-new/src/components/p-components/p-time/index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<script setup>
import { getPullViewAPI } from '@/api/common.js'
import { reactive } from 'vue'

const { proxy } = getCurrentInstance()

const props = defineProps({
  isShow: {
    type: Boolean,
    default: false
  },

  title: {
    type: String,
    default: '物料'
  }
})

const ruleForm = reactive({ pullDate: '' })

const addFormRef = ref(null)

// 排程单校验规则
const rules = reactive({
  pullDate: [{ required: true, message: '请选择拉取时间', trigger: 'change' }]
})

const emit = defineEmits(['selectsubmit', 'preservation', 'cancel', 'reset', 'materialTypeChange'])

// 提交
const preservation = async () => {
  const valid = await addFormRef.value.validate()
  if (!valid) {
    proxy.warningMsg('请填写完整')
    return false
  }
  emit('preservation', ruleForm)
}

const getTime = async () => {
  try {
    const res = await getPullViewAPI()
    ruleForm.pullDate = res.data.pullDate
  } catch (error) {}
}

watch(
  () => props.isShow,
  val => {
    if (val) {
      getTime()
    }
  },
  {
    deep: true,
    immediate: true
  }
)
</script>
<template>
  <p-dialog :isBtn="false" v-model="props.isShow" title="拉取" @close="emit('cancel')" width="25rem">
    <el-form :model="ruleForm" ref="addFormRef" :rules="rules" :inline="true" label-width="100px">
      <el-form-item label="拉取时间" prop="pullDate">
        <el-date-picker
          v-model="ruleForm.pullDate"
          type="date"
          format="YYYY-MM-DD"
          placeholder="请选择拉取时间"
          value-format="YYYY-MM-DD"
        />
      </el-form-item>
    </el-form>

    <!-- 按钮 -->
    <div>
      <el-row class="Btn">
        <el-button type="success" @click="preservation">拉取</el-button>
        <el-button type="info" @click="emit('cancel')">取消</el-button>
      </el-row>
    </div>
  </p-dialog>
</template>

<style scoped lang="scss">
.Btn {
  margin-top: 10px;
  float: right;
}
</style>
